#!/bin/bash

IFS_BAK=$IFS
IFS="
"

inv="/home/xbmc/Gdrive/inventory/up2date"
tagalog="/home/xbmc/TagalogMovie/"



/bin/ls -l $tagalog | /usr/bin/cut -d ":" -f 2- | /usr/bin/cut -d " " -f 2- > $inv/invtagalog.txt

/bin/sed -i '1d' $inv/invtagalog.txt


echo "Generating TagalogMovies Inventory from Meta Data - `date`"
echo "Title;Year;Release Date;Studio;Director;Rating;Duration (sec);Height;Width;Audio Channel;Audio Codec;Video Codec;File Extention;File Size(kb)" > $inv/invtagalog.csv

for fn in `/bin/cat $inv/invtagalog.txt`; do
        xy="`/usr/bin/xml_grep title --text_only $tagalog/$fn/$fn.nfo` - `date`"
	echo "$xy"
	x="`/usr/bin/xml_grep title --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep year --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep releasedate --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep studio --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep director --text_only $tagalog/$fn/$fn.nfo|/bin/sed 'N;s/\n/ | /'`;`/usr/bin/xml_grep rating --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep durationinseconds --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep height --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep width --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep channels --text_only $tagalog/$fn/$fn.nfo`;`/usr/bin/xml_grep codec --text_only $tagalog/$fn/$fn.nfo|/bin/sed 'N;s/\n/;/'`;"
        z=`/usr/bin/du -l $tagalog/$fn/* | /usr/bin/sort -n -r  | /usr/bin/head -1 |/usr/bin/cut -d '/' -f 1`
        y=`/usr/bin/du -l $tagalog/$fn/* | /usr/bin/sort -n -r | /usr/bin/head -1 |/usr/bin/cut -d '/' -f 2-|/bin/sed 's/.*\(...\)$/\1/'`
        echo "$x$y;$z" >> $inv/invtagalog.csv
done

echo "DONE Generating - `date`"
IFS=$IFS_BAK
IFS_BAK=
